package com.swjd.type;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

//延时发送消息
public class ProducerThree {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        //消息发送者（生产着)
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        //发送给服务器地址
        producer.setNamesrvAddr("localhost:9876");
        //启动服务
        producer.start();
        for (int i = 1;i<13; i++) {
            String msg = ("这是第" + i + "条消息");
            Message message = new Message("topic3", "tag1", msg.getBytes());
            //设置message的延时时间等级
            message.setDelayTimeLevel(3);
            //发送延时消息
            SendResult result = producer.send(message);
        }

    }
}
